<?php echo $this->element('admin/admin_leftmenu'); ?>
<div id="left">     
    <div class="div_header"><?php __('View Password');?></div>
		<div class="div_content">
		<?php echo $this->Session->flash(); ?>
		<form method="post" id="resetpassword" action="javascript:void(0);">
			Enter Username to reset password&nbsp;<input type="text" id="username" name="data[username]">&nbsp;<input type="submit" name="submit" value="Search">
			<div style="padding-top:10px;" id="msgdiv"></div>
		</form>
		</div>
		<div class="div_bottom"></div>
</div>    
</div>
<script type="text/javascript">  
 jQuery(document).ready(function(){
	jQuery("form#resetpassword").submit(function(){
		uname=jQuery("#username").val();
		if(uname==""){
			alert("Please put a username to search.");
		}else{			
			data=jQuery("#resetpassword").serialize();
			jQuery.ajax({
				type: 'post',
				url: baseurl+"reset_passwords/search_username",
				data: data,
				dataType: 'json',
				success:function(msg){
					if(msg.message=="Yes"){
						//html='<input type="hidden" name="data[User][id]" value="'+msg.uid+'"><input type="text" name="data[User][password]" id="password"><a href="javascript:void(0);" id="genarate_password">Genarate Password</a><br><br><input type="submit" name="submit" value="Reset Password">';
                                                html='Password is: '+msg.pass;
					}else{
						html="<span style='color:red;'>User does not exists in the system.</span>";						
					}
					jQuery("#msgdiv").html(html);
				}
			});
		}
	})
	
	jQuery("#genarate_password").live('click',function(){
		jQuery.ajax({
				type: 'post',
				url: baseurl+"reset_passwords/genarate_password",
				data: data,
				dataType: 'json',
				success:function(msg){
					if(msg.password){
						jQuery("#password").val(msg.password);
					}				
				}
			});	
	
	})
 });
 </script>